import { ListView } from 'antd-mobile'
let dataItem = [
  {
    title: '申银万国天天增1号集合资产计划',
    code: 'A58888'
  },
  {
    title: '申银万国灵通快利7天集合资产管理计划X类44第三期',
    code: 'A56666',
    type: 'OTO'
  },
  {
    title: '申万宏源证券有限公司金樽377(6天)收益凭证产品',
    code: 'A53333',
    type: 'OTO'
  },
  {
    title: '申银万国灵通快利7天集合资产管理计划(周周盈)',
    code: 'A51234',
    type: 'OTO'
  },
  {
    title: '申银万国灵通丰利720天11002号集合资产管理',
    code: 'A59999'
  },
  {
    title: '申万宏源证券有限公司金樽377(90天)收益凭证产品',
    code: 'A54321',
    type: 'OTO'
  },
  {
    title: '申万宏源证券有限公司金樽377(90天)收益凭证产品',
    code: 'A54321',
    type: 'OTO'
  },
  {
    title: '申银万国灵通快利7天集合资产管理计划(周周盈)',
    code: 'A51234',
    type: 'OTO'
  },
  {
    title: '申银万国天天增1号集合资产计划',
    code: 'A58888'
  },
  {
    title: '申银万国灵通快利7天集合资产管理计划X类44第三期',
    code: 'A56666',
    type: 'OTO'
  },
]
const dataSource = new ListView.DataSource({
  rowHasChanged: (row1, row2) => { 
    console.log(row1,row2)
    return row1 !== row2
  }
})
export default {
  namespace: 'contractSign',
  state: {
    sign:false,
    dataSource:{},
    height: document.documentElement.clientHeight * 3 / 4,
    contract:{
      agree:false,
      clauseAgree:false
    }
  },
  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen((location) => {
        // 用户刷新页面时候请求编排接口
        if (location.pathname === '/contractSign') {
          // 给dataSource赋值
          dispatch({
            type: 'getDataSource',
            payload: {
            }
          })
          dispatch({
            type: 'modules/getModules',
            payload: {
              pathname: '',
              businessId: '1231241224',
              process: 'contractSign',
              title: '电子合同签署'
            }
          })
        }
      })
    }
  },
  effects: {
    * getSign ( { payload } , {put}) {
      yield put({
        type: 'changeSign',
        payload
      })
    },
  },
  reducers: {
    changeSign (state, { payload:{sign} }) {
      return {
        ...state,
        sign
      }
    },
    // 适当性或者不适当性模块的同意按钮
    changeAgree (state, { payload:{contract} }) {
      return {
        ...state,
        contract
      }
    },
    // 条款同意的按钮
    clauseAgree (state, { payload: {contract} }) {
      return {
        ...state,
        contract
      }
    },
    getDataSource (state, { payload }) {
      if (Object.keys(payload).length !== 0) {
       dataItem.push(payload)
      }
      // let newDataItem = dataItem
      // for (let i = 0; i < count; i++) {
      //   newDataItem = newDataItem.concat(dataItem)
      //   console.log(1233)
      // }
      console.log(dataItem)
      return {
        ...state,
        dataSource:dataSource.cloneWithRows(dataItem),
      }
    }
  }
}